Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[58105] Added update_item and delete_branch methods to HierarchicalItemService #16939

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

apfohl
Copy link
Member

@apfohl apfohl commented Oct 11, 2024

Ticket

https://community.openproject.org/projects/openproject/work_packages/58105/github

What are you trying to accomplish?

See headline

What approach did you choose and why?

same as last time

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@apfohl apfohl requested review from mereghost and Kharonus October 11, 2024 12:59
app/models/custom_field/hierarchy/item.rb Outdated Show resolved Hide resolved
item = CustomField::Hierarchy::Item
.create(parent: validation[:parent], label: validation[:label], short: validation[:short])
def create_child_item(validation:)
item = validation[:parent].children.create(label: validation[:label], short: validation[:short])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Hmm, not sure, but I do not like this change. What is the benefit? Before the code was very clear, that a new Item is created. Now I must understand, that the item to create is referenced here as .children.

🔴 Does this even work, if the created item is not the only child?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that's how closure_tree works. It keeps intermediate representations of the tree for lookup, so we need to go through its code.

From another perspective, it is clearer to the random RoR dev as children.create maps to "I'm creating some associated record to the caller". :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm, that this does not break, if the parent already has persisted children, when adding a new one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It works. Why? Because .children is an association proxy that don't override anything but ensure that the fields for the association are correctly set - and in case of closure tree, sets up the rest of the fields and optimizations.

apfohl and others added 2 commits October 15, 2024 16:44
# Conflicts:
#	app/contracts/custom_fields/hierarchy/insert_item_contract.rb
#	spec/contracts/custom_fields/hierarchy/insert_item_contract_spec.rb
@mereghost mereghost force-pushed the implementation/58105-item-persistence-service branch from 103b927 to 160b3e6 Compare October 15, 2024 14:46
Copy link
Member

@Kharonus Kharonus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM generally, can you answer the last two questions though?

@mereghost mereghost force-pushed the implementation/58105-item-persistence-service branch from 35083ad to 2e27526 Compare October 16, 2024 16:09
@mereghost mereghost force-pushed the implementation/58105-item-persistence-service branch from 2e27526 to 9670a16 Compare October 16, 2024 17:06
@mereghost mereghost merged commit f9bd798 into dev Oct 16, 2024
11 checks passed
@mereghost mereghost deleted the implementation/58105-item-persistence-service branch October 16, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants